package com.kristin.reg;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName RegTest
 * @Description TODO
 * @Author Kristin
 * @Date 2020/09/23 09:18:49
 * @Version 1.0.0
 */
public class RegTest {

    public static void main(String[] args) throws Exception {
        Pattern pattern = Pattern.compile("/data/3/(\\d*)/call_list/20200924_人工_(\\d*)_委外池案件列表（催米）");
        String fileName = "/data/3/2/call_list/20200924_人工_2_委外池案件列表（催米）.xls";
        Matcher matcher = pattern.matcher(fileName);
        if(matcher.find()) {
            int count = matcher.groupCount();
            if(count >= 1) {
                Set<String> repeatFlagSet = new HashSet<>();
                // 判断是否相等
                for(int i = 1 ; i <= count ; i ++) {
                    System.out.println(matcher.group(i));
                    repeatFlagSet.add(matcher.group(i));
                    if(repeatFlagSet.size() > 1) {
                        throw new Exception("批次序号获取失败,文件路径和文件名中包含的批次序号不一致");
                    }
                }
            } else {
                throw new Exception("批次序号获取失败");
            }
        }
    }

}
